package action;

import data.Float2;

public class DefinedMovement {
	private MovimentAction mov;
	private float speed;
	private int actualPosIndex;
	private int lastPosIndex;
	private Float2[] positions;
	private boolean isMoving;
	
	public DefinedMovement (float speed, Float2[] positions)
	{
		mov = new MovimentAction();
		this.speed = speed;
		this.positions = positions;
		actualPosIndex = 0;
	}
	
	public Float2 Update(double elapsedTime)
	{
		return mov.link(positions[lastPosIndex], (float)elapsedTime);
	}
	
	public void MoveBack()
	{
		if (actualPosIndex > 0)
		{
			lastPosIndex = actualPosIndex;
			
			actualPosIndex--;
			mov.start(positions[actualPosIndex], positions[lastPosIndex], speed);
			setMoving(true);
		}
	}
	
	public void MoveFoward()
	{
		
		if (actualPosIndex < positions.length-1)
		{
			lastPosIndex = actualPosIndex;
			
			actualPosIndex++;
			mov.start(positions[actualPosIndex], positions[lastPosIndex], speed);
			setMoving(true);
		}
	}

	/**
	 * @return the isMoving
	 */
	public boolean isMoving() {
		return isMoving;
	}

	/**
	 * @param isMoving the isMoving to set
	 */
	public void setMoving(boolean isMoving) {
		this.isMoving = isMoving;
	}
	/**
	 * @return the speed
	 */
	public float getSpeed() {
		return speed;
	}

	/**
	 * @param speed the speed to set
	 */
	public void setSpeed(float speed) {
		this.speed = speed;
	}

	/**
	 * @return the position
	 */
	public int getPosition() {
		return actualPosIndex;
	}

	/**
	 * @param position the position to set
	 */
	public void setPosition(int position) {
		this.actualPosIndex = position;
	}

	/**
	 * @return the positions
	 */
	public Float2[] getPositions() {
		return positions;
	}

	/**
	 * @param positions the positions to set
	 */
	public void setPositions(Float2[] positions) {
		this.positions = positions;
	}
	
}
